package com.jimmy.medical.controller;

import com.jimmy.medical.entity.*;
import com.jimmy.medical.service.IDiagnoseFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.FeeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/diagnoseFlow")
public class DiagnoseFlowOrderController {

    @Autowired
    private IDiagnoseFlowOrderService diagnoseFlowOrderService;

    /**
     * 接号
     *
     * @param userId
     * @return
     * @param： flowOrderId
     */
    @RequestMapping("/accept")
    @ResponseBody
    public AjaxResult<Long> accept(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveAcceptInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/noticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> noticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/messageToCustomer")
    @ResponseBody
    public AjaxResult<Long> messageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveMessageFlow(message);
            }
        });
    }

    /**
     * 取号
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/takeNo")
    @ResponseBody
    public AjaxResult<Long> takeNo(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveTakeNoInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 自检仪容
     *
     * @param flowOrderId
     * @param userId
     * @param photoId
     * @return
     */
    @RequestMapping("/checkAppearance")
    @ResponseBody
    public AjaxResult<Long> checkAppearance(final Long flowOrderId, final Long userId, final Long photoId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveAppearance(flowOrderId, userId, photoId);
            }
        });
    }

    /**
     * 费用处理界面
     *
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goFeeProcess")
    @ResponseBody
    public AjaxResult<FeeInfo> goFeeProcess(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<FeeInfo>() {
            @Override
            public FeeInfo invoke() throws Exception {
                return diagnoseFlowOrderService.getMemberFeeInfo(flowOrderId);
            }
        });
    }

    /**
     * 费用处理
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/feeProcess")
    @ResponseBody
    public AjaxResult<Long> feeProcess(final Long flowOrderId, final Long userId) {
        if (diagnoseFlowOrderService.isFeeProcess(flowOrderId)) {
            //已处理
            return AjaxUtils.process(new Func_T<Long>() {
                @Override
                public Long invoke() throws Exception {
                    return diagnoseFlowOrderService.saveFeeProcess(flowOrderId, userId);
                }
            });
        } else {
            AjaxResult result = new AjaxResult();
            result.setSuccess(false);
            result.setMessage("当前用户存在未处理费用,无法提交费用处理");
            return result;
        }
    }

    /**
     * 陪诊
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/diagnose")
    @ResponseBody
    public AjaxResult<Long> diagnose(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveDiagnose(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 添加陪诊记录
     *
     * @param record
     * @param exceptionData
     * @param diagnoseData
     * @param medicineData
     * @return
     */
    @RequestMapping("/diagnoseRecord")
    @ResponseBody
    public AjaxResult<Long> diagnoseRecord(final OrderExecutionRecord record, final String exceptionData, final String diagnoseData, final String medicineData) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return diagnoseFlowOrderService.saveDiagnoseRecord(record, exceptionData, diagnoseData, medicineData);
            }
        });
    }

    /**
     * 修改陪诊记录
     *
     * @param record
     * @param exceptionData
     * @param diagnoseData
     * @param medicineData
     * @return
     */
    @RequestMapping("/updateDiagnoseRecord")
    @ResponseBody
    public AjaxResult<String> updateDiagnoseRecord(final OrderExecutionRecord record, final String exceptionData, final String diagnoseData, final String medicineData) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                diagnoseFlowOrderService.saveDiagnoseRecord(record, exceptionData, diagnoseData, medicineData, false);
                return "200";
            }
        });
    }

    /**
     * 完成陪诊
     *
     * @return
     */
    @RequestMapping("/submitDiagnose")
    @ResponseBody
    public AjaxResult<String> submitDiagnose(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                diagnoseFlowOrderService.submitDiagnose(flowOrderId, userId);
                return "200";
            }
        });
    }
}
